package org.jeecg.modules.rental.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.rental.entity.Assets;
import org.jeecg.modules.rental.mapper.AssetsMapper;
import org.jeecg.modules.rental.resp.AssetInfoResponse;
import org.jeecg.modules.rental.service.IAssetsService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 资产表
 * @Author: jeecg-boot
 * @Date:   2025-02-28
 * @Version: V1.0
 */
@Service
public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> implements IAssetsService {




    @Override
    public AssetInfoResponse getAssetInfo(String ownerId ) {
        // 使用 LambdaQueryWrapper 查询资产信息
        Assets assets = baseMapper.selectOne(new LambdaQueryWrapper<Assets>()
                .eq(Assets::getOwnerId, ownerId)  ); // 条件：ownerId 等于传入值


        // 如果未找到资产信息，返回 null
        if (assets == null) {
            return null;
        }

        // 封装返回结果
        AssetInfoResponse response = new AssetInfoResponse();
        response.setInvestAmount(assets.getTotalInvestment().doubleValue()); // 设置总投资金额
        response.setInvestNum(assets.getTotalRevenue().doubleValue());       // 设置总投资数量
        response.setRevenue(assets.getTotalRevenue().doubleValue());         // 设置总收益
        response.setBalance(assets.getTotalBalance().doubleValue());         // 设置余额
        return response;
    }
}
